var showButtonMenu = function(element){
	
	var option = initRightMenu(element);
	
	var changeLabel = dojo.create("div",{
		innerHTML: "Change Button label: ",
		style:  "font-size: 13px; color: #aaaaaa;",
	});
	
	var inputLabel = dojo.create("input",{
		id: "inputLabel",
		style: "width: 200px; max-width: 200px; min-width: 200px;",
		value: dojo.byId(element.id).innerHTML,
	});
	
	dojo.connect(inputLabel, "onchange", function(){ 
		var buttonLabel = dojo.byId("inputLabel").value;
		dijit.byId(element.id).set("label", buttonLabel);
		addAttributeToElementInGUIDescriptor(GUIDescriptor, "label", buttonLabel, element.id);
	});
	
	var buttonActionLabel = dojo.create("div",{
		innerHTML: "Choose the button action: ",
		style:  "font-size: 13px; color: #aaaaaa;",
	});
	
	var buttonActionSelector = dojo.create("select",{
		onchange: function(){
			addAttributeToElementInGUIDescriptor(GUIDescriptor, "buttonAction", this.value, element.id);
			dojo.setStyle(this, "display", "none");
			dojo.setStyle(buttonActionLabel, "display", "none");
			drawOtherOption(element, option, this.value);
		},
	});
	
	var buttonActionOptEmpty = dojo.create("option",{});
	buttonActionSelector.appendChild(buttonActionOptEmpty);
	var buttonActionOpt1 = dojo.create("option",{value: "sendForm", innerHTML: "Send form"});
	buttonActionSelector.appendChild(buttonActionOpt1);
	
	option.appendChild(changeLabel);
	option.appendChild(inputLabel);
	
	option.appendChild(buttonActionLabel);
	option.appendChild(buttonActionSelector);
};

var drawOtherOption = function(element, option, actionType){
	
	switch(actionType){
	
	case "sendForm":
		
		var formLabel = dojo.create("div",{
			innerHTML: "Select the form to send:",
			style:  "font-size: 13px; color: #aaaaaa;",
		});
		
		var formSelector = dojo.create("select",{
			onchange: function(){
					
				var items = getChildrenElement(GUIDescriptor, this.value);
				var that = {};
				
				for(var i=0; i<items.length; i++){
					dojo.subscribe("loadWS/"+items[i].id, items[i], function(data){
						
						if(getElement(GUIDescriptor, element.id).attributes["parameters"] == null){
							var param = {};
							param[(this.attributes).label] = data;
							getElement(GUIDescriptor, element.id).attributes["parameters"] = param;
						}else{
							var param = {};
							param[(this.attributes).label] = data;
							dojo.mixin(getElement(GUIDescriptor, element.id).attributes["parameters"], param);
						}
					} );
				}
			},
		});
		
		var elementInView = getChildrenElement(GUIDescriptor, "View"+pageSelector.value);
		
		var optEmpty = dojo.create("option",{});
		formSelector.appendChild(optEmpty);
		for(var i=0; i<elementInView.length; i++){
			if(elementInView[i].element == "roundRectList"){
				var opt = dojo.create("option",{value: elementInView[i].id, innerHTML: elementInView[i].id});
				formSelector.appendChild(opt);
			}
		}
		
		var wsLabel = dojo.create("div",{
			innerHTML: "Specify the URL of the webservice to call:",
			style:  "font-size: 13px; color: #aaaaaa;",
		});
		
		var wsInput = dojo.create("input",{type: "text", value: "http://localhost:8282/GUIEngine/rest/ws/findAuto"});
		
		var wsButton = dojo.create("button", {
			innerHTML: "Connect with webservice",
			onclick: function(){
				addAttributeToElementInGUIDescriptor(GUIDescriptor, "wsURL", wsInput.value, element.id);
				addAttributeToElementInGUIDescriptor(GUIDescriptor, "formToSend", formSelector.value, element.id);
			},
		});
		
		option.appendChild(formLabel);
		option.appendChild(formSelector);
		
		option.appendChild(wsLabel);
		option.appendChild(wsInput);
		option.appendChild(wsButton);
		
		dojo.connect(dijit.byId(element.id), "onClick", function(element){
			var mobileButton = getElement(GUIDescriptor, this.id);
			var args = dojo.toJson(mobileButton.attributes.parameters);
			
			wsPost(	getElement(GUIDescriptor, this.id).attributes.wsURL, args, function(data){
							var w = dijit.byId("View"+pageSelector.value);
							w.performTransition('#View2',1,"flip",null);
							dojo.publish("newData/"+getElement(GUIDescriptor, mobileButton.id).attributes.formToSend, data);
							},
					{"Content-Type": "text/plain"}
				);
		});
		
		break;
	}
};